//*****************************************************************************
//**************** (C) 2008 by Eleven Engineering Incorporated ****************
//*****************************************************************************
//**
//**		Tabs:	This file looks best with tab stops set every 6 spaces.
//**
//*****************************************************************************
//*****************************************************************************
//**
//** File:		common_data.asm
//** Project:	Simple Sample Project for WHAM4 Alpha
//** Revised:	v0.0.3
//**
//** Description:	
//**
//*****************************************************************************
//*****************************************************************************
//==============================================================

//-----------------------------------------------
//		Thread Definitions
#define	_Thread0		0
#define	_Thread1     	1
#define	_Thread2          2
#define	_Thread3          3
#define	_Thread4          4
#define	_Thread5          5
#define	_Thread6          6
#define	_Thread7          7

//-----------------------------------------------
//		THREAD ALLOCATION
#define	_ApplicationManager_ThreadA		_Thread0
#define	_ApplicationManager_ThreadB		_Thread1
#define	_ApplicationManager_ThreadC		_Thread2
#define	_ApplicationManager_ThreadD		_Thread3
//#define	_AudioLinkManager_ThreadD		_Thread4		// Compression Chan 0
//#define	_AudioLinkManager_ThreadE		_Thread5		// Compression Chan 1
#define	_RFLinkManager_ThreadA			_Thread6
#define	_RFLinkManager_ThreadB			_Thread7
//-----------------------------------------------

//-----------------------------------------------
//		Stack Pointer Allocation
RFLinkManager_ThreadA_SP		=		T6_SP
RFLinkManager_ThreadB_SP		=		T7_SP

//-----------------------------------------------
//		Semaphore Allocation
#define	_SCU_semaphore		15
#define	_RFLM_semaphore		1

//-----------------------------------------------
//		Other System Parameters
#define	_StackSize			20		//set the stack size reserved for each thread to 24 words


//==============================================================
//I/O pin definitions

	#define	_LED1					0		//PC0
	#define	_LED2					1		//PC1

	#define	_VolUpBit				6		//PD6
	#define	_VolDownBit				7		//PD7
	#define	_Button1				6		//PC6
	#define	_Button2				7           //PC7

	

//==============================================================
// I2C pin Definitions
	#define 	I2C_SCL		1
	#define 	I2C_SDA		0
	#define	I2C_PRT		GPFout
	#define	I2C_CFG		GPFcfg

	#define	_SDA			0
	#define	_SCL			1


//==============================================================
//EEPROM storage
#define	_EEPROMsize_bytes				32768		//32768 = 16 kwords; 16384 =  8 kwords
//#define	_EEPROMwriteLocation			_EEPROMsize_bytes - 22


//==============================================================
// Miscellaneous

//Timer B PWM parameters
#define	_PWM_Period			500	// Number of steps set in such a way we have a 3Hz increment per each step

//
#define	_RFLM_implementation		3	//
//#define	_AM_implementation		3	//


//==============================================================
//the following are definitions of data tables that exist in the mask ROM
#define	RFchannelEncodeTable_6_8 	0x2513
#define	RFchannelDecodeTable_6_8	0x2553

//==============================================================
//		CC2400 interface I/O definitions
//==============================================================

// 	#define	_channelSpacing		1	
	#define	_CC2400_CSn			0		//PE
	#define	_CC2400_TX			2		//PE
	#define	_CC2400_RX			3		//PE
      #define	_CC2400_Lock		1		//PE
                                                        
//	#define	_CC2400_GIO1		4		//PE
//	#define	_CC2400_GIO6		1		//PE
#define	_BBUdirection		2	//PH2
	
// since channel table is created only the first odd and even channels need to be defined
//#ifdef	_18.432MHz
//	#define	_CC2400_RFchannel1 		2084			//2401 MHz
//#else
//	#define	_CC2400_RFchannel1 		2134			//2401 MHz
//#endif

#define	_MAIN_regAddr		0x00
#define	_FSCTRL_regAddr   	0x01
#define	_FSDIV_regAddr		0x02 
#define	_MDMCTRL_regAddr     	0x03 
#define	_AGCCTRL_regAddr     	0x04 
#define	_FREND_regAddr       	0x05 
#define	_RSSI_regAddr        	0x06 
#define	_FREQEST_regAddr     	0x07 
#define	_IOCFG_regAddr       	0x08 
#define	_FSMTC_regAddr      	0x0B 
#define	_RESERVED_regAddr    	0x0C 
#define	_MANAND_regAddr      	0x0D 
#define	_FSMSTATE_regAddr    	0x0E 
#define	_ADCTST_regAddr      	0x0F 
#define	_RXBPFTST_regAddr    	0x10 
#define	_PAMTST_regAddr      	0x11 
#define	_LMTST_regAddr       	0x12 
#define	_MANOR_regAddr       	0x13 
#define	_MDMTST0_regAddr     	0x14 
#define	_MDMTST1_regAddr     	0x15 
#define	_DACTST_regAddr      	0x16 
#define	_AGCTST0_regAddr     	0x17 
#define	_AGCTST1_regAddr     	0x18 
#define	_AGCTST2_regAddr     	0x19 
#define	_FSTST0_regAddr      	0x1A 
#define	_FSTST1_regAddr      	0x1B 
#define	_FSTST2_regAddr      	0x1C 
#define	_FSTST3_regAddr      	0x1D 
#define	_MANFIDL_regAddr     	0x1E 
#define	_MANFIDH_regAddr     	0x1F 
#define	_GRMDM_regAddr       	0x20 
#define	_GRDEC_regAddr      	0x21 
#define	_PKTSTATUS_regAddr   	0x22 
#define	_INT_regAddr        	0x23 
#define	_SYNCL_regAddr       	0x2C 
#define	_SYNCH_regAddr       	0x2D 

#define	_SXOSCON_regAddr 		0x60
#define	_SFSON_regAddr		0x61
#define	_SRX_regAddr            0x62
#define	_STX_regAddr            0x63
#define	_SRFOFF_regAddr         0x64
#define	_SXOSCOFF_regAddr       0x65
            
#define	_FIFOREG			0x70


//#define	_20dB_BW_Test
//=============================================================================
//		RFLP Signalling Modes
//=============================================================================
	#define	_RFLP_CreateChannel_SignallingMode			0
	#define	_RFLP_NegotiatingChannel_SignallingMode		1
	#define	_RFLP_Idle_SignallingMode				2
	#define	_RFLP_Active_SignallingMode				3
	#define	_RFLP_ActiveAudio_SignallingMode			4
	#define	_RFLP_ActivePassiveAudio_SignallingMode		5
	#define	_RFLP_Unused_SignallingMode				6
	#define	_RFLP_Test_SignallingMode				7
	#define	_RFLP_Standby_SignallingMode				-1


//=============================================================================
//		RFLP Extended data messages sent by Master
//=============================================================================
	#define	_RFLP_msg_ConnectReq					0b10000|1
	#define	_RFLP_msg_ConnectFeatureReq				0b10000|2
	#define	_RFLP_msg_ConnectAcceptReq				0b10000|3

//=============================================================================
//		RFLP data messages sent by Master
//=============================================================================
	#define	_RFLP_ChannelKeyDataMessage				0b100
	#define	_RFLP_AudioSampleClockMessage				0b101


//=============================================================================
//		RFLP Extended data messages sent by Slave
//=============================================================================
	#define	_RFLP_msg_ConnectReply					0b10000|1
	#define	_RFLP_msg_ConnectFeatureReply				0b10000|2
	#define	_RFLP_msg_ConnectAcceptReply				0b10000|3


//=============================================================================
//		RFLP protocol timing parameters
//	see excel spreadsheet in documention for details on generation of these parameters
//=============================================================================
	#define 	_MstrPP_Start_BBUticks 			0   
	#define 	_MstrAP0_EDP_Start_BBUticks 		128 
	#define 	_MstrAP1_Start_BBUticks 		576 
	#define 	_MstrAP2_Start_BBUticks 		1024
	#define 	_MstrAP3_Start_BBUticks 		1472
	#define 	_MstrAP4_Start_BBUticks 		1920
	#define 	_MstrAP5_Start_BBUticks 		2368
	#define 	_MstrAP6_Start_BBUticks 		2816
	#define 	_MstrAP7_Start_BBUticks 		3264
	#define 	_MstrAP8_Start_BBUticks 		3712
	#define 	_MstrAP9_Start_BBUticks 		4160
	#define 	_MstrAP10_Start_BBUticks 		4608
	#define 	_MstrAP11_Start_BBUticks 		5056
	#define 	_Slv0RFcal_Start_BBUticks 		5518
	#define 	_Slv0RP_Start_BBUticks 			5566
	#define 	_Slv1RFcal_Start_BBUticks 		5662
	#define 	_Slv1RP_Start_BBUticks 			5724
	#define 	_RFChannelChange_Start_BBUticks 	5820

	#define 	_MstrPP_End_BBUticks 			128 
	#define 	_MstrAP0_EDP_End_BBUticks 		576
	#define 	_MstrAP1_End_BBUticks 			1024
	#define 	_MstrAP2_End_BBUticks 			1472
	#define 	_MstrAP3_End_BBUticks 			1920
	#define 	_MstrAP4_End_BBUticks 			2368
	#define 	_MstrAP5_End_BBUticks 			2816
	#define 	_MstrAP6_End_BBUticks 			3264
	#define 	_MstrAP7_End_BBUticks 			3712
	#define 	_MstrAP8_End_BBUticks 			4160
	#define 	_MstrAP9_End_BBUticks 			4608
	#define 	_MstrAP10_End_BBUticks 			5056
	#define 	_MstrAP11_End_BBUticks 			5504
	#define 	_Slv0RFcal_End_BBUticks 		5566
	#define 	_Slv0RP_End_BBUticks 			5662
	#define 	_Slv1RFcal_End_BBUticks 		5724
	#define 	_Slv1RP_End_BBUticks 			5820
	#define 	_RFChannelChange_End_BBUticks 	6000

//	#define 	_MstrPP_Timeout_BBUticks 		64  
	#define 	_MstrAP0_EDP_Timeout_BBUticks 	326 
//	#define 	_MstrAP1_Timeout_BBUticks 		774 
//	#define 	_MstrAP2_Timeout_BBUticks 		1222
//	#define 	_MstrAP3_Timeout_BBUticks 		1670
//	#define 	_MstrAP4_Timeout_BBUticks 		2118
//	#define 	_MstrAP5_Timeout_BBUticks 		2566
//	#define 	_MstrAP6_Timeout_BBUticks 		3014
//	#define 	_MstrAP7_Timeout_BBUticks 		3462
//	#define 	_MstrAP8_Timeout_BBUticks 		3910
//	#define 	_MstrAP9_Timeout_BBUticks 		4358
//	#define 	_MstrAP10_Timeout_BBUticks 		4806
//	#define 	_MstrAP11_Timeout_BBUticks 		5254
//	#define 	_Slv0RFcal_Timeout_BBUticks 		5534
	#define 	_Slv0RP_Timeout_BBUticks 		5643
//	#define 	_Slv1RFcal_Timeout_BBUticks 		5692
	#define 	_Slv1RP_Timeout_BBUticks 		5793




//=============================================================================
//		Misc. RFLP protocol parameters
//=============================================================================
	#define	_RFLP_RFchannelSequenceLength			20
	#define	_RFLP_RFchannelNumberTotal			34
	#define	_RFLP_MstrPollCycleLength_BBUticks		6000
	#define	_RFLP_AFH_RFchannelQualityThreshold		5
	#define	_RFLP_RadioLockup_Timeout_BBUticks		135


//=============================================================================
//		experimental stuff for improved coexistence with fixed channel devices(802.11,DSSS phones ...)
//=============================================================================
//	#define	_forceAFHeventPeriodicallyWithNoBadChannelAssessment
//	#define	_forceAFHeventPeriodciallyWhenCloseWithNoBadChannelAssessment
	#define	_RFLP_periodic_AFA_EventCounterSize			11251		//2000=10.6 seconds, 11251=~60s
//	#define	_enableAFA
//	#define	_enable_RSSIcoexistenceAdjustment


#define		_customerID_MSB		0x00
#define		_customerID_LSB		0x11

// since channel table is created only the first odd and even channels need to be defined
#define	_CC2400_RFchannel0 		2094 + 0	+ 0
#define	_CC2400_RFchannel1 		2094 + 2	+ 0
#define	_CC2400_RFchannel2 		2094 + 4	+ 0
#define	_CC2400_RFchannel3 		2094 + 6	+ 0
#define	_CC2400_RFchannel4 		2094 + 8	+ 0
#define	_CC2400_RFchannel5 		2094 + 10	+ 0
#define	_CC2400_RFchannel6 		2094 + 12	+ 0
#define	_CC2400_RFchannel7 		2094 + 14	+ 0
#define	_CC2400_RFchannel8 		2094 + 16	+ 0
#define	_CC2400_RFchannel9 		2094 + 18	+ 0
#define	_CC2400_RFchannel10 		2094 + 0	+ 10
#define	_CC2400_RFchannel11 		2094 + 2	+ 10
#define	_CC2400_RFchannel12 		2094 + 4	+ 10
#define	_CC2400_RFchannel13 		2094 + 6	+ 10
#define	_CC2400_RFchannel14 		2094 + 8	+ 10
#define	_CC2400_RFchannel15 		2094 + 10	+ 10
#define	_CC2400_RFchannel16 		2094 + 12	+ 10
#define	_CC2400_RFchannel17 		2094 + 14	+ 10
#define	_CC2400_RFchannel18 		2094 + 16	+ 10
#define	_CC2400_RFchannel19 		2094 + 18	+ 10
#define	_CC2400_RFchannel20 		2094 + 0	+ 20
#define	_CC2400_RFchannel21 		2094 + 2	+ 20
#define	_CC2400_RFchannel22 		2094 + 4	+ 20
#define	_CC2400_RFchannel23 		2094 + 6	+ 20
#define	_CC2400_RFchannel24 		2094 + 8	+ 20
#define	_CC2400_RFchannel25 		2094 + 10	+ 20
#define	_CC2400_RFchannel26 		2094 + 12	+ 20
#define	_CC2400_RFchannel27 		2094 + 14	+ 20
#define	_CC2400_RFchannel28 		2094 + 16	+ 20
#define	_CC2400_RFchannel29 		2094 + 18	+ 20
#define	_CC2400_RFchannel30 		2094 + 0	+ 30
#define	_CC2400_RFchannel31 		2094 + 2	+ 30
#define	_CC2400_RFchannel32 		2094 + 4	+ 30
#define	_CC2400_RFchannel33 		2094 + 6	+ 30
#define	_CC2400_RFchannel34 		2094 + 8	+ 30
#define	_CC2400_RFchannel35 		2094 + 10	+ 30
#define	_CC2400_RFchannel36 		2094 + 12	+ 30
#define	_CC2400_RFchannel37 		2094 + 14	+ 30